package com.xlf.common.core.util.file;

import com.xlf.common.core.enums.FileTypeEnum;

/**
 * 媒体类型工具类
 *
 * @author
 */
public class MimeTypeUtils
{
    public static final String IMAGE_PNG = "image/png";

    public static final String IMAGE_JPG = "image/jpg";

    public static final String IMAGE_JPEG = "image/jpeg";

    public static final String IMAGE_BMP = "image/bmp";

    public static final String IMAGE_GIF = "image/gif";

    public static final String[] IMAGE_EXTENSION = { "bmp", "gif", "jpg", "jpeg", "png" };

    public static final String[] FLASH_EXTENSION = { "swf", "flv" };

    public static final String[] MEDIA_EXTENSION = { "swf", "flv", "mp3", "wav", "wma", "wmv", "mid", "avi", "mpg",
            "asf", "rm", "rmvb" };

    public static final String[] VIDEO_EXTENSION = { "mp4", "avi", "rmvb" };

    public static final String[] DEFAULT_ALLOWED_EXTENSION = {
            // 图片
            "bmp", "gif", "jpg", "jpeg", "png",
            // word excel powerpoint
            "doc", "docx", "xls", "xlsx", "ppt", "pptx", "html", "htm", "txt",
            // 压缩文件
            "rar", "zip", "gz", "bz2",
            // 视频格式
            "mp4", "avi", "rmvb",
            // pdf
            "pdf" };

    public static String getExtension(String prefix)
    {
        switch (prefix)
        {
            case IMAGE_PNG:
                return "png";
            case IMAGE_JPG:
                return "jpg";
            case IMAGE_JPEG:
                return "jpeg";
            case IMAGE_BMP:
                return "bmp";
            case IMAGE_GIF:
                return "gif";
            default:
                return "";
        }
    }




    /**
     *
     *根据扩展名判断是不是图片
     * @param type 文件扩展名
     * @return
     */
    public static boolean imageJudge(String type) {

        if(type.equals("bmp")||type.equals("jpg")||type.equals("jpeg")||type.equals("png")){
            return true;
        }
        return false;
    }

    /**
     * 判断是不是音乐
     * @param type
     * @return
     */
    public static boolean musicJudge(String type){
        if (type.equals("mp3") || type.equals("mpeg") || type.equals("vma") || type.equals("aac") || type.equals("ra") || type.equals("am") || type.equals("rmx")
                || type.equals("ape") || type.equals("flac")) {
            return true;
        }
        return false;

    }

    /**
     * 判断是不是视频
     * @param type
     * @return
     */
    public static boolean videoJudge(String type){
        if (type.equals("avi") || type.equals("mov") || type.equals("wmv") || type.equals("rmvb") || type.equals("rm") || type.equals("mp4") || type.equals("3gp") || type.equals("flv")) {
            return true;
        }
        return false;
    }
    /**
     * 判断是不是文本
     * @param type
     * @return
     */
    public static boolean textJudge(String type){
        if(type.equals("txt"))
            return true;
        return false;
    }
    /**
     * 判断是不是md
     * @param type
     * @return
     */
    public static boolean mdJudge(String type){
        if(type.equals("md"))
            return true;
        return false;
    }

    public static boolean docJudge(String type){
        if(type.equals("docx"))
            return true;
        return false;
    }
    public static boolean zipJudge(String type){
        if(type.equals("zip")||type.equals("rar")||type.equals("jar")||type.equals("war"))
            return true;
        return false;
    }

    public static int byExNameGetType(String type){

        if(imageJudge(type))
            return FileTypeEnum.IMAGE.getType();
        else if(textJudge(type))
            return FileTypeEnum.TEXT.getType();
        else if(musicJudge(type))
            return FileTypeEnum.MUSIC.getType();
        else if(videoJudge(type))
            return FileTypeEnum.VIDEO.getType();
        else if(docJudge(type))
            return FileTypeEnum.DOC.getType();
        else if(zipJudge(type))
            return FileTypeEnum.PACK.getType();
        return FileTypeEnum.OTHER.getType();
    }

}
